﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Home.Master" Inherits="System.Web.Mvc.ViewPage" %>

<%@ Import Namespace="WebHoiChoMuaBan.Models" %>
<%@ Import Namespace="WebHoiChoMuaBan.Controllers.Helpers" %>
<%@ Import Namespace="WebHoiChoMuaBan.Controllers.Utility" %>
<asp:Content ID="Content2" ContentPlaceHolderID="TitleHolder" runat="server">
    Rao vặt sản phẩm
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="HeadHolder" runat="server">
    <script type="text/javascript">
        $(document).ready(function () {
            var right = $('#nbright').height();
            var left = $('#nbleft').height();
            if (left > right)
                $('#nbright').height(left);
            else
                $('#nbleft').height(right + 3);

        });
    </script>
    <script>
        $(document).ready(function () {
            var triggers = $(".modalInput").overlay({

                // some mask tweaks suitable for modal dialogs
                mask: {
                    color: '#ebecff',
                    loadSpeed: 200,
                    opacity: 0.9
                },

                closeOnClick: false
            });

            var buttons = $("#yesno button").click(function (e) {

                // get user input
                var yes = buttons.index(this) === 0;

                // do something with the answer
                triggers.eq(0).html("You clicked " + (yes ? "yes" : "no"));
            });

            $("#prompt form").submit(function (e) {

                // close the overlay
                triggers.eq(1).overlay().close();

                // get user input
                var input = $("input", this).val();

                // do something with the answer
                triggers.eq(1).html(input);

                // do not submit the form
                return e.preventDefault();
            });
        });
    </script>
</asp:Content>
<%--Minh Thêm--%>
<%--List Menu Header--%>
<%--copy từ maincontent lên ListMenu--%>
<asp:Content ID="Content4" ContentPlaceHolderID="ListMenuHeader" runat="server">
    <!-- Group list menu -->
    <div id="nbleft" style="float: left; width: 194px; background-color: #EEF2F5; border: 1px solid #d8dfea;">
        <img src='../Content/Images/hoi_bg_listmenu_nhadat.png' height="150px" width="150px"
            style="margin: 8px 8px 8px 20px" />
    </div>
    <div id="nbright" style="float: right; width: 80%">
        <div class="hoicho_group_product">
            <div class="hoicho_header_feature">
                <ul>
                    <%
                        string bold = "style='font-weight: bold'";
                        PageType curPage = (PageType)ViewData["CurrentPage"];
                        Category curCate = (Category)ViewData["CurrentCategory"];
                        int needSell = (int)ViewData["NeedSell"];
                        int provinceId = (int)ViewData["ProvinceId"];

                        List<Category> cate = (List<Category>)ViewData["Categories"];
                        int i;
                        foreach (Category c in cate)
                        {
                            bool isCurrent = curCate != null &&
                                                ((curCate.ParentCategory != null && c.CateId == curCate.ParentCategory.CateId) ||
                                                 c.CateId == curCate.CateId);
                            Response.Write(string.Format("<li class='{0}'><a href='{1}?pid={2}&cid={3}&p={4}&need={5}&prvid={6}'>{7}</a></li>",
                                                        (isCurrent ? "selected_menu" : string.Empty),
                                                        Url.Action("Page", "Home", new { pageName = MiscUtil.EscapeString(curPage.PageName) }),
                                                        curPage.PageId,
                                                        c.CateId,
                                                        1,
                                                        needSell,
                                                        provinceId,
                                                        c.CateName));
                        }
                    %>
                </ul>
            </div>
            <div class="hoicho_feature_content">
                <div class="private_breakpage_replycoment col_left reset_margin">
                    <%
                        Response.Write(string.Format("<a {0} href='{2}?pid={3}&cid={4}&p={5}&need={6}&prvid={8}'>Cần bán</a> | <a {1} href='{2}?pid={3}&cid={4}&p={5}&need={7}&prvid={8}'>Cần mua</a>",
                                                        (needSell == NewsProductHelper.NEED_SELL ? bold : string.Empty),
                                                        (needSell == NewsProductHelper.NEED_BUY ? bold : string.Empty),
                                                        Url.Action("Page", "Home", new { pageName = MiscUtil.EscapeString(curPage.PageName) }),
                                                        curPage.PageId,
                                                        (curCate != null ? curCate.CateId : 0),
                                                        1,
                                                        NewsProductHelper.NEED_SELL,
                                                        NewsProductHelper.NEED_BUY,
                                                        provinceId));
                    %>
                </div>
                <div class="hoicho_select_province col_right">
                    <span class="hoicho_margin_right">
                        <%
                            StringBuilder provLinks = new StringBuilder();
                            provLinks.Append("<a {0} href='{4}?pid={5}&cid={6}&p={7}&need={8}&prvid=2'>Hà Nội</a> | ");
                            provLinks.Append("<a {1} href='{4}?pid={5}&cid={6}&p={7}&need={8}&prvid=6'>Hải Phòng</a> | ");
                            provLinks.Append("<a {2} href='{4}?pid={5}&cid={6}&p={7}&need={8}&prvid=3'>Hồ Chí Minh</a> | ");
                            provLinks.Append("<a {3} href='{4}?pid={5}&cid={6}&p={7}&need={8}&prvid=5'>Đà Nẵng</a> |");
                            Response.Write(string.Format(provLinks.ToString(),
                                                    (provinceId == 2 ? bold : string.Empty), // {0}
                                                    (provinceId == 6 ? bold : string.Empty), // {1}
                                                    (provinceId == 3 ? bold : string.Empty), // {2}
                                                    (provinceId == 5 ? bold : string.Empty), // {3}
                                                    Url.Action("Page", "Home", new { pageName = MiscUtil.EscapeString(curPage.PageName) }),
                                                    curPage.PageId,
                                                    (curCate != null ? curCate.CateId : 0),
                                                    1,
                                                    needSell // buy or sell
                                                    ));
                        %>
                    </span><span>
                        <%--  <select id="cbbProvince" class="hoicho_input_select_province">--%>
                        <%
                            string selected = "class='highlight'";
                        %>
                        <a class="modalInput" style="cursor:pointer" rel="#prompt">
                            Tỉnh Khác</a>
                        <script type="text/javascript">
                            $("a[title]").tooltip();
                        </script>
                        <%--</select>--%>
                        <div class="modalpro" id="prompt">
                            <button type="button" class="close" style="float:right;border:none;cursor:pointer">
                                Đóng
                            </button>
                            <br />
                            <table>
                                <tr>
                                    <%
                                        List<Province> provinces = (List<Province>)ViewData["Provinces"];
                                        int k = 0;
                                        
                                        foreach (Province pr in provinces)
                                        {
                                            //Response.Write(string.Format("<option value='{0}' {2}>{1}</option>", 
                                            //                            pr.ProvId, 
                                            //                            pr.ProvName,
                                            //                            (provinceId == pr.ProvId ? selected : string.Empty)
                                            //                            ));
                                    %>
                                    <td>
                                        <%Response.Write(string.Format("<a {7} href='{0}?pid={1}&cid={2}&p={3}&need={4}&prvid={5}'>{6}</a>", Url.Action("Page", "Home", new { pageName = MiscUtil.EscapeString(curPage.PageName) }), curPage.PageId, (curCate != null ? curCate.CateId : 0), 1, needSell, pr.ProvId, pr.ProvName,pr.ProvHighlight==1? selected:String.Empty)); %>
                                    </td>
                                    <%
k++;
if (k % 3 == 0)
{
                                    %>
                                </tr>
                                <tr>
                                    <%
}
                                    %>
                                    <%
}
                                    %>
                                </tr>
                            </table>
                        </div>
                        <%--   <script type="text/javascript">
                            jQuery("#cbbProvince").change(function () {
                                location.href=<%=string.Format("'{0}?pid={1}&cid={2}&p={3}&need={4}'",
                                                    Url.Action("Page", "Home", new { pageName = MiscUtil.EscapeString(curPage.PageName) }),
                                                    curPage.PageId,
                                                    (curCate != null ? curCate.CateId : 0),
                                                    1,
                                                    needSell // buy or sell
                                                    ) %> + '&prvid=' + jQuery(this).val();
                            });
                        </script>--%>
                    </span>
                </div>
            </div>
        <%
                //int j = 1;
                //foreach (Category c in cate)
                {
                    //Response.Write(string.Format("<div id='cate_{1}' class='hoicho_group_listmenu_fation page_{2}' {0}>", (j>1 ? "style='display:none'" : string.Empty), c.CateId, c.PageId));
                    Response.Write("<div>");
                    //j++;

                    if (curCate != null)
                    {
                        List<CategoryHelper.SubCategory> subcategories = null;
                        if (curCate.SubCategories != null && curCate.SubCategories.Count > 0)
                        {
                            //Số dòng mỗi cột
                            subcategories = (from sub in curCate.SubCategories
                                             select new CategoryHelper.SubCategory
                                             {
                                                 id = sub.CateId,
                                                 name = sub.CateName
                                             }).ToList();
                        }
                        else if (curCate.ParentCategory != null)
                        {
                            subcategories = (from sub in curCate.ParentCategory.SubCategories
                                             select new CategoryHelper.SubCategory
                                             {
                                                 id = sub.CateId,
                                                 name = sub.CateName
                                             }).ToList();
                        }

                        if (subcategories != null)
                        {
                            int perRow = (int)Math.Ceiling((double)subcategories.Count / 4);

                            //4 cột subcategories
                            for (i = 0; i < 4; i++)
                            {
                                var subCate = (from sub in subcategories select sub).Skip(perRow * i).Take(perRow);
                                if (subCate != null)
                                {
                                    Response.Write("<div class='private_menu_list_product'><ul>");
                                    foreach (var s in subCate)
                                        Response.Write(string.Format("<li><img src='../Content/Images/arrow_listproduct.gif'/><a href='{0}?pid={1}&cid={2}&p={3}' style='font-weight: {4}'>{5}</a></li>",
                                                                        Url.Action("Page", "Home", new { pageName = MiscUtil.EscapeString(curPage.PageName) }),
                                                                        curPage.PageId,
                                                                        s.id,
                                                                        1,
                                                                        ((curCate != null && curCate.CateId == s.id) ? "bold" : "normal"),
                                                                        s.name));
                                    Response.Write("</ul></div>");
                                }
                            }
                        }
                    }
                    Response.Write("</div>");
                }
        %>
    </div>
    </div>
    <div class="clr">
    </div>
    <!-- End Group list menu -->
</asp:Content>
<%--end List Menu Header--%>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContentHolder" runat="server">
    <!-- Group san pam noi bat -->
   <%--  <div style="float:right" id="toggle">Thu Lại</div>
        <div class="clr"></div>--%>
     <div class="hoicho_group_product" >
        <div class="hoicho_top_groupproduct">
        <div style="float:left">
            <p class="hoicho_texttop_product">
                Sản phẩm nổi bật</p>
                </div>
                 <div style="float:right;cursor:pointer" id="toggle"><img src="../Content/Images/collapse.png" width="20" height="20"/></div>
                  <div class="clr"></div>
        </div>
        <div class="hoicho_group_product_content" id="sanphamnoibat">
            <%
                NewsProductHelper.FetchProductResult lstHot = (NewsProductHelper.FetchProductResult)ViewData["HotProducts"];
                int i = 1;
                foreach (var hot in lstHot.products)
                {
                    if (i++ != 5)
                        Response.Write("<div class='hoicho_product_thumb'>");
                    else
                        Response.Write("<div class='hoicho_product_thumb reset_margin'>");
            %>
            <!-- Product thumb -->
            <center>
            <% 
                        
                string link = string.Format("<a href='{0}?prid={1}'>",
                                    Url.Action("Detail", "NewsProduct", new { productTitle = MiscUtil.EscapeString(hot.NProTitle) }),
                                    hot.NProId
                                    );
            %>
            <%=link %>
            
            <img src="/../Content/Images/Upload/<%=(hot.NewsProductThumbs != null && hot.NewsProductThumbs.Count > 0 ? hot.NewsProductThumbs.First().NProThumbName : "" )%>"
                width="94" height="80" alt="" class="hoicho_img_productthumb" />
            </a>
            </center>
            <%-- <p class="font_bold" >--%>
            <%
                if (hot.NProTitle.Length > 40)
                {
                    Response.Write(string.Format("<p class='font_bold' title='{0}' >", hot.NProTitle));
                }
                else
                {
                   // Response.Write("<div style='height:36px !important'>");
                    Response.Write("<p class='font_bold' style='height:36px !important'>");
                }
            %>
            <%=link %>
            <%//Minh Thêm
/*-----------Truncate Product Title----------------*/
/*Thiết lập Title = 40 chars*/
if (hot.NProTitle.Length > 40)
{
    hot.NProTitle = hot.NProTitle.Substring(0, 37) + "...";
}
else
{
    int iCount = 40 - hot.NProTitle.Length;
    for (int k = 0; k < iCount; k++)
    {
        hot.NProTitle += " ";
    }
}
/*-----------End truncate Product Title*/ %>
            <%=hot.NProTitle %>
            </p>
           <%-- </div>--%>
             </a>
            <br />
            <p>
                <%
//Minh Thêm
/*-----------Truncate Product Provice Name----------------*/
/*Thiết lập Product Provice Name = 10 chars*/
//if (hot.Province.ProvName.Length > 10)
//{
//    hot.Province.ProvName = hot.Province.ProvName.Substring(0, 7) + "...";
//}
/*-----------End truncate Product Provice Name*/ %>
                Nơi rao:
                <%--<span class="hoicho_ograne_color">--%>
                <%if (hot.Province.ProvName.Length > 10)
                  {
                      Response.Write(String.Format("<span class='hoicho_ograne_color' title='{0}'>", hot.Province.ProvName));
                      hot.Province.ProvName = hot.Province.ProvName.Substring(0, 7) + "...";
                  }
                  else
                  {
                      Response.Write("<span class='hoicho_ograne_color'>");
                  } %>
                <%=hot.Province.ProvName%>
                <%Response.Write("</span"); %></p>
            <p>
                Ngày đăng: <span class="hoicho_ograne_color">
                    <%=hot.NProDate.ToString("dd/MM/yyyy") %></span></p>
            <div class="hoicho_bt_product_price">
                <%=(hot.NProPrice == null ? "Thương lượng" : hot.NProPrice.Value + " " + hot.NProPriceUnit) %></div>
            <p>
                <img src="/../Content/Images/hoicho_icon_view.gif" alt="" /><span class="hoicho_margin_leftright">Lượt
                    xem:</span><span class="hoicho_margin_leftright hoicho_ograne_color"><%=hot.NProViewCount %></span></p>
            <p>
                <img src="/../Content/Images/hoicho_icon_savenews.gif" alt="" class="hoicho_margin_leftright" /><a
                    href="#" class="SaveButton" onclick="SaveNews(<%=hot.NProId %>)" data-url='<%=hot.NProId %>'>Lưu tin</a></p>
            <%
Response.Write("</div>");
                }
            %>
            <!-- End Product thumb -->
  
        </div>
        <script type="text/javascript">
            $(".hoicho_group_product_content p[title]").tooltip();
            $(".hoicho_group_product_content span[title]").tooltip();
        </script>
    </div>
        <!-- End Group san pam noi bat -->
    <!-- End Group san pam noi bat -->
    <a name="noibat"></a>

      <!-- Group san pham moi -->
        <div class="hoicho_group_product">
            <table width="100%" border="0">
                <tr>
                    <td colspan="2" class="hoicho_top_groupproduct">
                        <p class="hoicho_texttop_product">
                            Sản phẩm mới</p>
                    </td>
                    <td width="15%" align="left" bgcolor="#F5F7FB" class="hoicho_border_bottom">
                        <strong>Tỉnh/T.Phố</strong>
                    </td>
                    <td width="12%" align="right" bgcolor="#F5F7FB" class="hoicho_border_bottom" style="padding-right:20px">
                        <strong>Xem</strong>
                    </td>
                    <td width="4%" align="center" bgcolor="#F5F7FB" class="hoicho_border_bottom">
                        <strong>Ảnh</strong>
                    </td>
                </tr>
                <%
                    NewsProductHelper.FetchProductResult lstNew = (NewsProductHelper.FetchProductResult)ViewData["NewProducts"];
                    i = 0;
                    foreach (NewsProduct n in lstNew.products)
                    {
                        if (i % 2 == 0)
                            Response.Write("<tr bgcolor='#fafafa'>");
                        else
                            Response.Write("<tr bgcolor='#e0f0ff'>");
                        i++;
                        
                        string link = string.Format("<a href='{0}?prid={1}'>",
                                            Url.Action("Detail", "NewsProduct", new { productTitle = MiscUtil.EscapeString(n.NProTitle) }),
                                            n.NProId                                            
                                            );
                     %>
                    <td valign="top" >
                        <%=link %>
                            <img src="/../Content/Images/hoicho_arrow_newproduct.gif" alt="" />
                        </a>
                    </td>
                    <td valign="top">
                        <%=link %>
                            <%=n.NProTitle %></a>
                    </td>
                    <td valign="top">
                        <%=string.Format("<a href='{0}'>{1}</a>", n.Province.ProvId, n.Province.ProvName) %>
                        
                    </td valign="top">
                    <td align="right"  style="padding-right:20px">
                        <%=n.NProViewCount %>
                    </td>
                    <td valign="top">
                        <img src="/../Content/Images/Upload/<%=(n.NewsProductThumbs != null && n.NewsProductThumbs.Count > 0 ? n.NewsProductThumbs.First().NProThumbName : "" )%>" alt="" width="24" height="22" />
                    </td>
                <%
                        Response.Write("</tr>");
                    }
                         %>
            </table>
        </div>
    
        <!-- End Group san pham moi -->

    <div class="private_breakpage" style="text-align: right">
        <%
            PageType curPage = (PageType)ViewData["CurrentPage"];
            Category curCate = (Category)ViewData["CurrentCategory"];
            NewsProductHelper.FetchProductResult lstNews = (NewsProductHelper.FetchProductResult)ViewData["NewProducts"];
            int p;
            if (Request.QueryString["p"] != null && int.TryParse(Request.QueryString["p"], out p))
            {
        %>
        <% if (p > 1)
           { %><a href='<%=string.Format("{0}?pid={1}&cid={2}&p={3}#noibat'",
                                                    Url.Action("Page", "Home", new { pageName = MiscUtil.EscapeString(curPage.PageName) }),
                                                    curPage.PageId,
                                                    Request.QueryString["cid"],
                                                    p-1) %>'><img src="/../Content/Images/arrow_breakpage_left.gif" alt="">&nbsp;Trang
               trước</a>
        <% } %>
        <%
if (p > 3)
    Response.Write(string.Format("<a href='{0}?pid={1}&cid={2}&p={3}#noibat' {4}>{5}</a> ",
                                    Url.Action("Page", "Home", new { pageName = MiscUtil.EscapeString(curPage.PageName) }),
                                    curPage.PageId,
                                    Request.QueryString["cid"],
                                    1,
                                    string.Empty,
                                     1));
if (p > 4)
    Response.Write("...");
int total = lstNews.totalPages;
int from = (p - 2 < 1 ? 1 : p - 2);
int to = (p + 2 >= total ? total : p + 2);
for (i = from; i <= to; i++)
    Response.Write(string.Format("<a href='{0}?pid={1}&cid={2}&p={3}#noibat' {4}>{5}</a> ",
                                    Url.Action("Page", "Home", new { pageName = MiscUtil.EscapeString(curPage.PageName) }),
                                    curPage.PageId,
                                    Request.QueryString["cid"],
                                    i,
                                    (i == p ? "class='menu_select'" : string.Empty),
                                     i));
if (p <= total - 4)
    Response.Write("...");
if (p <= total - 3)
    Response.Write(string.Format("<a href='{0}?pid={1}&cid={2}&p={3}#noibat' {4}>{5}</a> ",
                                    Url.Action("Page", "Home", new { pageName = MiscUtil.EscapeString(curPage.PageName) }),
                                    curPage.PageId,
                                    Request.QueryString["cid"],
                                    total,
                                    string.Empty,
                                    total));
        %>
        <% if (p < lstNews.totalPages)
           { %><a href='<%=string.Format("{0}?pid={1}&cid={2}&p={3}#noibat'",
                                                    Url.Action("Page", "Home", new { pageName = MiscUtil.EscapeString(curPage.PageName) }),
                                                    curPage.PageId,
                                                    Request.QueryString["cid"],
                                                    p+1) %>'>Trang sau&nbsp;<img src="/../Content/Images/arrow_breakpage_right.gif" alt=""></a>
        <% } %>
        <% }  %>
    </div>
    <%
        i = 0;
        foreach (NewsProduct n in lstNews.products)
        {
    %>
    <div class="private_thumb_listpr">
        <div class="private_img_post_bt">
            <%--<a href="<%=Url.Action("Detail", "NewsProduct", new {newsId=n.NProId})%>">--%>
            <% string link = string.Format("<a href='{0}?prid={1}'>",
                                            Url.Action("Detail", "NewsProduct", new { productTitle = MiscUtil.EscapeString(n.NProTitle) }),
                                            n.NProId
                                            );
            %>
            <%=link %>
            <img class="private_img_post hoicho_margin_topbottom" src="/../Content/Images/Upload/<%=(n.NewsProductThumbs != null && n.NewsProductThumbs.Count > 0 ? n.NewsProductThumbs.First().NProThumbName : "" )%>"
                width="140" height="101" /></a></div>
        <div class="private_post_text">
            <p class="private_text_title" style="width:450px">
                <%=link %>
                <%=n.NProTitle %>
                </a>
            </p>
            <p class="hoicho_margin_topbottom" style="width: 450px">
                <%=n.NProIntro%>
            </p>
            <p class="hoicho_margin_topbottom">
                <a href="#">
                    <%=n.Member.MemUsername %></a> <span class="hoicho_timer_rate">-
                        <%=n.Province.ProvName %>
                        -
                        <%=n.NProDate.ToString("dd/MM/yyyy hh:mm") %></span></p>
                            <div class="private_logo_share col_left hoicho_margin_right">
                            <!-- AddToAny BEGIN -->
                            <div class="a2a_kit a2a_default_style">
                                <a class="a2a_dd" href="http://www.addtoany.com/share_save?linkurl=hoichomuaban.com&amp;linkname=Hoi%20Cho%20Mua%20Ban">
                                    Chia sẻ</a> <span class="a2a_divider"></span><a class="a2a_button_facebook">
                                </a><a class="a2a_button_twitter"></a><a class="a2a_button_google_bookmarks"></a>
                                <a class="a2a_button_digg"></a>
                                <!-- AddToAny END -->
                            </div>
                        </div>
            <div class="private_friend_chat bg_reset">
                <span class="hoicho_margin_right"><strong>Giá bán:&nbsp;</strong> <span class="private_price">
                    <%=(n.NProPrice == null ? "Thương lượng" : n.NProPrice.Value + " " + n.NProPriceUnit) %></span>
                </span>
            </div>
        </div>
        <div class="hoicho_list_reviews">
            <%--  <div>
                <input type="submit" style="#width: 100px;" id="Submit1" value="Đánh giá" class="private_bt_submit_news_disable">
            </div>--%>
            <div>
                <a href="#" class="hoicho_margin_topbottom">
                    <img alt="" src="/../Content/Images/button_member.gif"></a></div>
            <div>
                <p>
                    <a href="#" onclick="SaveNews(<%=n.NProId %>)">
                        <img src="../Content/Images/sanphamdanhdau.jpg" />
                        </a></p>
            </div>
        </div>
    </div>
    <!-- End thumb list sp -->
    <%
}
    %>
    <div class="private_breakpage" style="text-align: right">
        <%
            if (Request.QueryString["p"] != null && int.TryParse(Request.QueryString["p"], out p))
            {
        %>
        <% if (p > 1)
           { %><a href='<%=string.Format("{0}?pid={1}&cid={2}&p={3}#noibat'",
                                                    Url.Action("Page", "Home", new { pageName = MiscUtil.EscapeString(curPage.PageName) }),
                                                    curPage.PageId,
                                                    Request.QueryString["cid"],
                                                    p-1) %>'><img src="/../Content/Images/arrow_breakpage_left.gif" alt="">&nbsp;Trang
               trước</a>
        <% } %>
        <%
            if (p > 3)
                Response.Write(string.Format("<a href='{0}?pid={1}&cid={2}&p={3}#noibat' {4}>{5}</a> ",
                                                Url.Action("Page", "Home", new { pageName = MiscUtil.EscapeString(curPage.PageName) }),
                                                curPage.PageId,
                                                Request.QueryString["cid"],
                                                1,
                                                string.Empty,
                                                 1));
            if (p > 4)
                Response.Write("...");
            int total = lstNews.totalPages;
            int from = (p - 2 < 1 ? 1 : p - 2);
            int to = (p + 2 >= total ? total : p + 2);
            for (i = from; i <= to; i++)
                Response.Write(string.Format("<a href='{0}?pid={1}&cid={2}&p={3}#noibat' {4}>{5}</a> ",
                                                Url.Action("Page", "Home", new { pageName = MiscUtil.EscapeString(curPage.PageName) }),
                                                curPage.PageId,
                                                Request.QueryString["cid"],
                                                i,
                                                (i == p ? "class='menu_select'" : string.Empty),
                                                 i));
            if (p <= total - 4)
                Response.Write("...");
            if (p <= total - 3)
                Response.Write(string.Format("<a href='{0}?pid={1}&cid={2}&p={3}#noibat' {4}>{5}</a> ",
                                                Url.Action("Page", "Home", new { pageName = MiscUtil.EscapeString(curPage.PageName) }),
                                                curPage.PageId,
                                                Request.QueryString["cid"],
                                                total,
                                                string.Empty,
                                                total));
        %>
        <% if (p < lstNews.totalPages)
           { %><a href='<%=string.Format("{0}?pid={1}&cid={2}&p={3}#noibat'",
                                                    Url.Action("Page", "Home", new { pageName = MiscUtil.EscapeString(curPage.PageName) }),
                                                    curPage.PageId,
                                                    Request.QueryString["cid"],
                                                    p+1) %>'>Trang sau&nbsp;<img src="/../Content/Images/arrow_breakpage_right.gif" alt=""></a>
        <% } %>
        <% }  %>
    </div>
</asp:Content>
